package org.poptest.processor.phase;

import org.poptest.Callback;
import org.poptest.model.Context;
import org.poptest.model.FieldNode;
import org.poptest.processor.Phase;
import org.poptest.processor.Processor;
import org.poptest.processor.annotation.AnnotationProcessor;

import java.lang.reflect.Field;

/**
 * @author Alan Roche
 *         Date: 12/02/11
 *         Time: 18:53
 */
public class FieldsProcessor extends PhaseProcessor {
    public FieldsProcessor(final AnnotationProcessor... annotationProcessors) {
        super(Phase.FIELDS, annotationProcessors);
    }

    protected void doProcess(final Context context) {
        context.getTestInstance().foreachField(new Callback<FieldNode>() {
            public void execute(final FieldNode fieldNode) {
                context.setFieldNode(fieldNode);
                for (final Processor processor : getAnnotationProcessors()) {
                    processor.process(context);
                }
            }
        });
    }
}
